<?php
session_start();
if (!isset($_SESSION['timer_data'])) {
    $_SESSION['timer_data'] = [
        'start_time' => null,
        'is_running' => false,
        'elapsed_time' => 0,
        'blue_score' => 0,
        'red_score' => 0
    ];
}

$timerData = $_SESSION['timer_data'];
$currentTime = $timerData['elapsed_time'];
if ($timerData['is_running']) {
    $currentTime += (time() - $timerData['start_time']);
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>计时器控制中心</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            max-width: 600px;
            margin: 0 auto;
            background: white;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            text-align: center;
            color: #333;
        }
        .control-links {
            display: flex;
            flex-direction: column;
            gap: 15px;
            margin: 20px 0;
        }
        .control-link {
            display: block;
            padding: 20px;
            border-radius: 10px;
            text-align: center;
            font-size: 20px;
            font-weight: bold;
            text-decoration: none;
            color: white;
            box-shadow: 0 4px 8px rgba(0,0,0,0.2);
            transition: all 0.2s;
        }
        .control-link:active {
            transform: scale(0.98);
        }
        .blue-link {
            background-color: #3b82f6;
        }
        .red-link {
            background-color: #ef4444;
        }
        .admin-link {
            background-color: #10b981;
        }
        .timer-info {
            margin-top: 20px;
            padding: 15px;
            background-color: #f9fafb;
            border-radius: 8px;
            text-align: center;
        }
        .timer-display {
            font-size: 24px;
            font-family: monospace;
            margin: 10px 0;
        }
        .score-info {
            display: flex;
            justify-content: space-around;
            margin: 15px 0;
        }
        .blue-info, .red-info {
            padding: 10px;
            border-radius: 6px;
            font-weight: bold;
        }
        .blue-info {
            background-color: #dbeaff;
            color: #1e40af;
        }
        .red-info {
            background-color: #fee2e2;
            color: #b91c1c;
        }
        .status {
            padding: 8px 15px;
            border-radius: 20px;
            display: inline-block;
            font-weight: bold;
        }
        .status-running {
            background-color: #dcfce7;
            color: #166534;
        }
        .status-stopped {
            background-color: #fee2e2;
            color: #b91c1c;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>计时器控制中心</h1>
        
        <div class="control-links">
            <a href="blue-control.php" class="control-link blue-link">蓝方控制</a>
            <a href="red-control.php" class="control-link red-link">红方控制</a>
            <a href="admin.php" class="control-link admin-link">管理员控制</a>
        </div>
        
        <div class="timer-info">
            <h3>当前状态</h3>
            <div class="timer-display"><?php echo gmdate("H:i:s", $currentTime); ?></div>
            
            <div class="score-info">
                <div class="blue-info">蓝方: <?php echo $timerData['blue_score']; ?>分</div>
                <div class="red-info">红方: <?php echo $timerData['red_score']; ?>分</div>
            </div>
            
            <div class="status <?php echo $timerData['is_running'] ? 'status-running' : 'status-stopped'; ?>">
                状态: <?php echo $timerData['is_running'] ? '运行中' : '已停止'; ?>
            </div>
        </div>
    </div>
</body>
</html>